package com.nzd.slsharing.exception;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(CustomExpiredException.class)
    public ResponseEntity<String> handleTokenExpiredException(CustomExpiredException ex) {
        // 返回 401 状态码（未授权）以及错误信息
        return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED);
    }

    // 其他通用异常处理
    @ExceptionHandler(Exception.class)
    public ResponseEntity<String> handleException(Exception ex) {
        return new ResponseEntity<>("系统异常，请稍后再试", HttpStatus.INTERNAL_SERVER_ERROR);
    }
}